package com.yztl.service.Client;

import com.yztl.mapper.client.ClientMapper;
import com.yztl.pojo.Client;
import com.yztl.pojo.Order;
import com.yztl.pojo.Product;
import com.yztl.pojo.Status;
import com.yztl.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ClientServiceImpl implements ClientService{
    @Resource
    private ClientMapper clientMapper;
    @Override
    public Client Clientlogin(String username, String pwd) {
        return clientMapper.Clientlogin(username,pwd);
    }

    @Override
    public void getPageProduct(PageUtil<Order> pageUtil, int id) {
        int count=clientMapper.getCount(id);
        pageUtil.setCounts(count);
        if(count>0){
            if(pageUtil.getPageIndex()>pageUtil.getPageCount()){//右边界
                pageUtil.setPageIndex(pageUtil.getPageCount());
            }
            int pageindex=(pageUtil.getPageIndex()-1)*pageUtil.getPageSize();
            int pagesize=pageUtil.getPageSize();
            pageUtil.setLists(clientMapper.getPageProduct(pageindex,pagesize,id));
        }else{
            pageUtil.setLists(new ArrayList<>());
        }
    }

    @Override
    public List<Status> getStatus() {
        return clientMapper.getStatus();
    }

    @Override
    public List<Product> getProduct() {
        return clientMapper.getProduct();
    }

    @Override
    public int deleteOrder(int id,int state) {

        return clientMapper.deleteOrder(id,state);
    }

    @Override
    public Order selOneOrder(int id) {
        return clientMapper.selOneOrder(id);
    }

    @Override
    public int updateOrder(Order order) {
        return clientMapper.updateOrder(order);
    }

    @Override
    public int addOrder(Order order) {
        return clientMapper.addOrder(order);
    }


}
